<?php

/* 店铺评论控制器 */
class StoreCommentApp extends BackendApp
{
    var $_storecomment_mod;

    function __construct()
    {
        $this->StoreCommentApp();
    }

    function StoreCommentApp()
    {
        parent::__construct();
        $this->_storecomment_mod =& m('storecomment');
    }

    function index()
    {
        $conditions = $this->_get_query_conditions(array(
            array(
                'field' => 'store_name',
                'equal' => 'LIKE',
            ),
            array(
                'field' => 'user_name',
                'equal' => 'LIKE',
            ),
            array(
                'field' => 'content',
                'equal' => 'LIKE',
            ),
        ));
        $page = $this->_get_page();
        $comments = $this->_storecomment_mod->find(array(
            'join' => 'belongs_to_store',
        	'fields'=>'sc.*,s.store_name',
            'conditions' => '1=1' . $conditions,
            'limit' => $page['limit'],
            'count' => true,
            'order' => 'sc.add_time desc',
        ));
        
        $this->assign('comments', $comments);
        //引入jquery表单验证插件
        $this->import_resource(array(
                                    'script' => 'jqtreetable.js',
                                    'style'  => 'res:style/jqtreetable.css'));
        $page['item_count'] = $this->_storecomment_mod->getCount();
        $this->_format_page($page);
        $this->assign('filtered', $conditions? 1 : 0); //是否有查询条件
        $this->assign('page_info', $page);

        $this->display('storecomment.index.html');
    }

    function view()
    {
        $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
        if (!$id)
        {
            $this->show_warning('Hacking Attempt');
            return;
        }

            /* 是否存在 */
            $comments = $this->_storecomment_mod->find(array(
            'join' => 'belongs_to_store',
        	'fields'=>'sc.*,s.store_name',
            'conditions' => 'comment_id='.$id,
        ));
            if (!$comments)
            {
                $this->show_warning('storecomment_empty');
                return;
            }
            foreach ($comments as $v){
            	$comment=$v;
            }
            $comment[pic]=explode(',', $comment['pic']);
            $this->assign('comment', $comment);
            $this->display('storecomment.form.html');
    }
    
    function drop()
    {
        $id = isset($_GET['id']) ? trim($_GET['id']) : '';
        if (!$id)
        {
            $this->show_warning('no_storecomment_to_drop');
            return;
        }

        $ids = explode(',', $id);
        if (!$this->_storecomment_mod->drop($ids))
        {
            $this->show_warning($this->_storecomment_mod->get_error());
            return;
        }

        $this->show_message('drop_ok');
    }
    function show()
    {
        $id = isset($_GET['id']) ? trim($_GET['id']) : '';
        if (!$id)
        {
            $this->show_warning('no_storecomment_to_show');
            return;
        }

        $ids = explode(',', $id);
        $this->_storecomment_mod->edit($ids,array('if_show'=>'1'));

        $this->show_message('show_ok');
    }
    function hide()
    {
        $id = isset($_GET['id']) ? trim($_GET['id']) : '';
        if (!$id)
        {
            $this->show_warning('no_storecomment_to_hide');
            return;
        }

        $ids = explode(',', $id);
        $this->_storecomment_mod->edit($ids,array('if_show'=>'0'));

        $this->show_message('hide_ok');
    }
}

?>
